#include "gui.h"
//initialization list
Gui::Gui() : 
  io( IOManager::getInstance() ),
  parser( "xmlSpec/menu.xml" ),
  buttons(), 
  clicks(),
  nextIcon(0),
  click(0) 
{

  string filename = parser.getXmlStr("startFile");

  filename = parser.getXmlStr("clickoffFile");
  SDL_Surface* surfaceOff(io.loadAndSet(filename, true));
  Frame clickoff(surfaceOff, 
              parser.getXmlInt("clickoffWidth"), 
              parser.getXmlInt("clickoffHeight"), 
              parser.getXmlInt("clickoffSrcX"), 
              parser.getXmlInt("clickoffSrcX")); 
  clicks.push_back( clickoff );

  filename = parser.getXmlStr("clickonFile");
  SDL_Surface* surfaceOn(io.loadAndSet(filename, true));
  Frame clickon(surfaceOn, 
              parser.getXmlInt("clickonWidth"), 
              parser.getXmlInt("clickonHeight"), 
              parser.getXmlInt("clickonSrcX"), 
              parser.getXmlInt("clickonSrcX")); 
  clicks.push_back( clickon );
}

void Gui::addButton(std::string name)
{
  float x = parser.getXmlInt(name + "X");
  float y = parser.getXmlInt(name + "Y");
  string filename = parser.getXmlStr(name + "File");
  SDL_Surface* surface(io.loadAndSet(filename, true));
  Frame frame(surface, 
            parser.getXmlInt(name + "Width"), 
            parser.getXmlInt(name + "Height"), 
            parser.getXmlInt(name + "SrcX"), 
            parser.getXmlInt(name + "SrcY")); 
  buttons.push_back( Button(name, frame, Vector2f(x, y)) );	
}

void Gui::draw(){
  Viewport& vp = Viewport::getInstance();
  int count = 0;
  for(std::vector<Button>::iterator it = buttons.begin(); it != buttons.end(); it++)
  {	
	(*it).frame.draw( vp.X() + 475, vp.Y() + 80 + (count * 90)  );
	(*it).position[0] = vp.X() + 475;
	(*it).position[1] = vp.Y() + 80 + (count * 90);
	count++;
  }
  
  Vector2f pos = buttons[nextIcon].position;
  clicks[click].draw( pos[0]-70, pos[1]+20);
}



